package com.demo.controller;

import com.demo.service.credit.CreditService;
import com.demo.service.credit.CreditServiceFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

// 控制器类
@RestController
public class CreditController {

    @Autowired
    private CreditServiceFactory creditServiceFactory;

    @GetMapping("/applyCredit")
    public String applyCredit(@RequestParam String productCode) {
        CreditService creditService = creditServiceFactory.getCreditService(productCode);
        if (creditService != null) {
            return creditService.applyCredit();
        } else {
            return "No credit service found for product code: " + productCode;
        }
    }
}